package cn.iocoder.yudao.module.fengdong.smartelderly.controller.app.dynamic;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.fengdong.smartelderly.controller.admin.dynamic.vo.*;
import cn.iocoder.yudao.module.fengdong.smartelderly.convert.dynamic.DynamicConvert;
import cn.iocoder.yudao.module.fengdong.smartelderly.dal.dataobject.dynamic.DynamicDO;
import cn.iocoder.yudao.module.fengdong.smartelderly.service.dynamic.DynamicService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "用户 APP - 老人动态管理")
@RestController
@RequestMapping("/fengdong.smartelderly/dynamic")
@Validated
public class AppDynamicController {

    @Resource
    private DynamicService dynamicService;

    @PostMapping("/create")
    @Operation(summary = "创建老人动态管理")
    public CommonResult<Long> createDynamic(@Valid @RequestBody DynamicCreateReqVO createReqVO) {
        return success(dynamicService.createDynamic(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新老人动态管理")
    public CommonResult<Boolean> updateDynamic(@Valid @RequestBody DynamicUpdateReqVO updateReqVO) {
        dynamicService.updateDynamic(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除老人动态管理")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteDynamic(@RequestParam("id") Long id) {
        dynamicService.deleteDynamic(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得老人动态管理")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<DynamicRespVO> getDynamic(@RequestParam("id") Long id) {
        DynamicDO dynamic = dynamicService.getDynamic(id);
        return success(DynamicConvert.INSTANCE.convert(dynamic));
    }

    @GetMapping("/list")
    @Operation(summary = "获得老人动态管理列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<DynamicRespVO>> getDynamicList(@RequestParam("ids") Collection<Long> ids) {
        List<DynamicDO> list = dynamicService.getDynamicList(ids);
        return success(DynamicConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得老人动态管理分页")
    public CommonResult<PageResult<DynamicRespVO>> getDynamicPage(@Valid DynamicPageReqVO pageVO) {
        PageResult<DynamicDO> pageResult = dynamicService.getDynamicPage(pageVO);
        return success(DynamicConvert.INSTANCE.convertPage(pageResult));
    }
}
